import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';

class TitleSection extends StatefulWidget {

  final String title;
  final String subtitle;
  final int starCount;

  const TitleSection({Key key, this.title, this.subtitle, this.starCount}) : super(key: key);

  @override
  _TitleSectionState createState() => _TitleSectionState();
}

class _TitleSectionState extends State<TitleSection> {

  int _count;

  @override
  void initState() {
    super.initState();
    _count = widget.starCount;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(32),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  padding: EdgeInsets.only(bottom: 8),
                  child: Text(
                    widget.title,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ),
                Text(
                  widget.subtitle,
                  style: TextStyle(color: Colors.grey[500]),
                )
              ],
            ),
          ),

          GestureDetector(
            child: Icon(
              Icons.star,
              color: Colors.red[500],
            ),
            onTap: (){
              BotToast.showText(text:"点赞成功", align: Alignment(0, 0));
              setState(() {
                _count += 1;
              });
            },
          ),
          Text(_count.toString())
        ],
      ),
    );
  }
}
